//
//  XBTabBar.swift
//  Sina
//
//  Created by 周旭斌 on 2017/3/23.
//  Copyright © 2017年 周旭斌. All rights reserved.
//

import UIKit

class XBTabBar: UITabBar {

    override init(frame: CGRect) {
        super.init(frame: frame);
        
        addSubview(composeButton);
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    // MARK:重新布局
    override func layoutSubviews() {
        super.layoutSubviews();
        
        let buttonW = ScreenWidth / CGFloat(tabBarCount);
        let buttonH = frame.size.height;
        
//        for subView in subviews {
//            XBLog(subView);
//            // 判断是否是UITabBarButton,并且当时第2个的时候改变位置
//            if subView.isKind(of: NSClassFromString("UITabBarButton")!) {
//                
//            }
//            
//        }
        
        composeButton.frame = CGRect(x: 2 * buttonW, y: 0, width: buttonW, height: buttonH);
    }
    
    // MARK:懒加载中间的加号按钮
    lazy var composeButton : UIButton = {
        () -> UIButton in
        let button = UIButton();
        button.setBackgroundImage(UIImage.init(named: "tabbar_compose_button"), for: UIControlState.normal);
        button.setBackgroundImage(UIImage.init(named: "tabbar_compose_button_highlighted"), for: UIControlState.highlighted);
        button.setImage(UIImage.init(named: "tabbar_compose_icon_add"), for: UIControlState.normal);
        button.setImage(UIImage.init(named: "tabbar_compose_icon_add_highlighted"), for: UIControlState.highlighted);
        return button;
    }()

}
